package com.epam.task.web.dao.impl.mysql;

import com.epam.task.web.dao.DAOFactory;
import com.epam.task.web.dao.impl.CustomerDAO;
import com.epam.task.web.db.ConnectionsPool;
import com.epam.task.web.db.exception.CannotTakeConnectionException;
import sun.jdbc.odbc.ee.ConnectionPool;

import java.sql.Connection;

/**
 * User: zhunusbekova.arailym
 */

public class MYSQLDAOFactory extends DAOFactory {
    private static ConnectionsPool pool = null;

    public void setConnectionPool(ConnectionsPool pool) {
        MYSQLDAOFactory.pool = pool;
    }
	private static synchronized Connection createConnection(){
    Connection con = null;
    try{
        con = pool.createConnection();
    } finally{
        // logger
    }
    return con;
}

    public CustomerDAO getCustomerDAO()
            throws CannotTakeConnectionException {
        Connection con = createConnection();
        if (con == null){
            throw new CannotTakeConnectionException();
        }
        return new MYSQLCustomerDAO(con);
    }

}



